package com.ruoyi.web.teacher;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.teacher.service.ITQuestionService;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teacher.domain.TQuestionBank;
import com.ruoyi.teacher.service.ITQuestionBankService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题库Controller
 *
 * @author ruoyi
 * @date 2024-11-30
 */
@RestController
@RequestMapping("/teacher/bank")
public class TQuestionBankController extends BaseController
{
    @Autowired
    private ITQuestionBankService tQuestionBankService;

    /**
     * 查询题库列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:bank:list')")
    @GetMapping("/list")
    public TableDataInfo list(TQuestionBank tQuestionBank)
    {
        startPage();
        List<TQuestionBank> list = tQuestionBankService.selectTQuestionBankList(tQuestionBank);
        return getDataTable(list);
    }

    /**
     * 导出题库列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:bank:export')")
    @Log(title = "题库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TQuestionBank tQuestionBank)
    {
        List<TQuestionBank> list = tQuestionBankService.selectTQuestionBankList(tQuestionBank);
        ExcelUtil<TQuestionBank> util = new ExcelUtil<TQuestionBank>(TQuestionBank.class);
        util.exportExcel(response, list, "题库数据");
    }

    /**
     * 获取题库详细信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:bank:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tQuestionBankService.selectTQuestionBankById(id));
    }

    /**
     * 新增题库
     */
    @PreAuthorize("@ss.hasPermi('teacher:bank:add')")
    @Log(title = "题库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TQuestionBank tQuestionBank)
    {
        return toAjax(tQuestionBankService.insertTQuestionBank(tQuestionBank));
    }

    /**
     * 修改题库
     */
    @PreAuthorize("@ss.hasPermi('teacher:bank:edit')")
    @Log(title = "题库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TQuestionBank tQuestionBank)
    {
        return toAjax(tQuestionBankService.updateTQuestionBank(tQuestionBank));
    }

    /**
     * 删除题库
     */
    @PreAuthorize("@ss.hasPermi('teacher:bank:remove')")
    @Log(title = "题库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tQuestionBankService.deleteTQuestionBankByIds(ids));
    }
//    deleteOne
    @DeleteMapping(value = "/deleteOne")
    public AjaxResult deleteOne(@RequestBody TQuestionBank qbQuestionBank ){

        tQuestionBankService.deleteBank(qbQuestionBank);

        return AjaxResult.success();
    }


}
